<template>
  <div>

    <el-container
      style="height: 525px; overflow: hidden; background: white; border:1px solid white ; border-radius: 8px; margin-top: 10px;">
      <div style="margin-top:10px;">
        <template>
          <el-table :data="tableData" style="width: 100%; height: 426px;  display: block;">
            <el-table-column prop="kuId" label="二级库存编号" width="235">
            </el-table-column>
            <el-table-column prop="proClass" label="产品分类" width="180">
            </el-table-column>
            <el-table-column prop="houseName" label="库房名称" width="120">
            </el-table-column>
            <el-table-column prop="oneArea" label="I级存储区域" width="120">
            </el-table-column>
            <el-table-column prop="twoArea" label="II级存储区域" width="200">
            </el-table-column>
            <el-table-column label="分配">
              <template slot-scope="scope">
                <el-button v-if="scope.row.houseName != null" type="info" size="mini" @click="setIIKuCun(scope.row)"
                  round>增加</el-button>
                <el-button v-if="scope.row.houseName == null" type="info" size="mini" round>分配</el-button>
              </template>
            </el-table-column>
            <el-table-column label="释放">
              <template slot-scope="scope">
                <el-button type="danger" size="mini" @click="handleDelete(scope.row)" round>释放</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="display: block; margin-top: 15px;">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum"
              :page-sizes="[1, 2, 6, 7]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          </div>
        </template>
      </div>
    </el-container>

    <el-dialog title="II级产品分类增加" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="II级产品分类" :label-width="formLabelWidth">
          <el-input v-model="form.proName" autocomplete="off" size="mini" disabled></el-input>
        </el-form-item>

        <el-form-item label="请选择库房" :label-width="formLabelWidth">
          <el-select v-model="form.repid" placeholder="请选择" size="mini" @change="choose(form.repid)">
            <el-option v-for="i  in listData" :key="i.repid" :label="i.houseName" :value="i.repid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="I级存储区域" :label-width="formLabelWidth">
          <el-input v-model="form.areaName" autocomplete="off" size="mini" disabled></el-input>
        </el-form-item>

        <el-form-item label="II级存储区域名称" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off" size="mini"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button style="width: 45px ; height: 30px;" @click="dialogFormVisible = false">取 消</el-button>
        <el-button style="width: 45px ; height: 30px;" type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  export default {
    name: 'repii',
    data() {
      return {
        pageNum: 1,
        pageSize: 7,
        total: 0,
        tableData: [],
        listData: [],
        dialogTableVisible: false,
        dialogFormVisible: false,
        form: {
          proName: '',
          repid: '',
          areaName: ''
        },
        formLabelWidth: '120px'
      }
    },
    methods: {
      tableRowClassName({
        row,
        rowIndex
      }) {
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        return '';
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.GetOnline(this.pageNum, this.pageSize);
      },
      handleCurrentChange(val) {
        this.pageNum = val;
        this.GetOnline(this.pageNum, this.pageSize);
      },
      GetOnline(pageNum, pageSize) {
        var data = new URLSearchParams();
        data.append("pageNum", pageNum);
        data.append("pageSize", pageSize);
        this.$http.post('rep/getKunCunII', data).then(res => {
          this.pageNum = res.data.pageNum;
          this.pageSize = res.data.pageSize;
          this.total = res.data.total;
          this.tableData = res.data.rows;
        }).catch(err => {
          console.log(err);
        })
      },
      //二级库存增加分配
      setIIKuCun(data) {

        this.$http.post('rep/proIIName?kuId=' + data.kuId).then(res => {
          this.form.proName = res.data;
        }).catch(err => {
          console.log(err);
        })

        this.$http.post('rep/proLisKucun?kuId=' + data.kuId).then(res => {
          this.listData = res.data;
        }).catch(err => {
          console.log(err);
        })
        this.dialogFormVisible = true;
      },
      choose(repid) {
        var datas= this.listData.filter(item => {
          if (item.repid == repid) {
            return true;
          }
        });

        this.form.areaName = datas[0].areaName;
      }
    },
    mounted() {
      this.GetOnline(this.pageNum, this.pageSize);
    }
  }
</script>

<style scoped="scoped">
  * {
    padding: 0px;
    margin: 0px;
  }

  .el-breadcrumb__inner {
    color: black;

  }

  .el-input {
    width: 340px;
  }

  .el-select {
    width: 340px;
  }

  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }

  .el-breadcrumb__item:last-child .el-breadcrumb__inner,
  .el-breadcrumb__item:last-child .el-breadcrumb__inner a,
  .el-breadcrumb__item:last-child .el-breadcrumb__inner a:hover,
  .el-breadcrumb__item:last-child .el-breadcrumb__inner:hover {
    font-weight: 400;
    color: black;
    cursor: text;
  }
</style>
